<?php
/**
 * 频道
 * Enter description here ...
 * @author nijn
 *
 */
class ChannelController extends FrontController{

	/**
	 * indexAction 频道首页
	 * listAction 频道列表
	 */
    
    //机场频道首页
	public $layout = '//layouts/platform_column';
	
	public function actionZjyIndex() {
		$this->render('zjyIndex');
	}
    public function actionAircraftIndex(){
        $this->render('aircraftIndex');
    }
    
    //景区频道首页
    public function actionScenicIndex(){
        $this->render('scenicIndex');
    }
    
    public function actionTicketList() {
    	$model = new Ticket('search');
    	$returnModel = new ReturnTicket('search');
    	$manner = isset($_GET['manner']) ? $_GET['manner'] : 'oneWay';
    	if (isset($_GET['Ticket'])) 
    		$model->attributes = $_GET['Ticket'];
    	if (isset($_GET['ReturnTicket']))
    		$returnModel->attributes = $_GET['ReturnTicket'];
    	$this->render('ticket/list',array(
    		'manner' => $manner,//方式：单程，往返
    		'data' => $model->listing()->search(),
			'model' => $model,
    		'returnData' => $returnModel->listing()->search(),
    		'returnModel' => $returnModel,
    	));
    }
    
    public function actions() {
		return array(
			/***************景区***************/
			'scenicWrite' => array(//景区门票订单填写
				'class' => 'application.components.actions.front.OrderAction',
				'view' => 'scenic/orderWrite',
				'returnUrl' => array('success')
			),
			'scenicList' => array(//景区门票列表
				'class' => 'application.components.actions.front.ListAction',
			    'view' => 'scenic/list',
				'modelName' => 'CompanyScenic',
				'criteria' => array(
					'scopes' => array(
						'noGoods','citySearch'
					)
				),
			),
			'scenicView' => array(//景区门票详情
			    'class' => 'application.components.actions.front.ViewAction',
			    'view' => 'scenic/view',
			    'modelName' => 'CompanyScenic',
			),
			/***************机票***************/
			'ticketWrite' => array(//机票订单填写
				'class' => 'application.components.actions.front.OrderAction',
				'view' => 'ticket/orderWrite',
				'returnUrl' => array('success')
			),
//			'ticketList' => array(//机票列表
//				'class' => 'application.components.actions.front.ListAction',
//			    'view' => 'ticket/list',
//			    'criteria' => array(
//					'scopes' => 'listing',
//				),
//				'modelName' => 'Ticket'
//			),
			/***************酒店***************/
			'hotelWrite' => array(//酒店客房订单填写
				'class' => 'application.components.actions.front.OrderAction',
				'view' => 'hotel/orderWrite',
				'returnUrl' => array('success')
			),
			'hotelList' => array(//酒店列表
				'class' => 'application.components.actions.front.ListAction',
			    'view' => 'hotel/list',
				'modelName' => 'CompanyHotel',
				'criteria' => array(
					'scopes' => 'noGoods'
				),
			),
			/***************旅游***************/
			'travelWrite' => array(//旅游订单填写
				'class' => 'application.components.actions.front.OrderAction',
				'view' => 'travel/orderWrite',
				'returnUrl' => array('success')
			),
			'travelList' => array(//旅游列表
				'class' => 'application.components.actions.front.ListAction',
			    'view' => 'travel/list',
				'modelName' => 'Travel',
				'criteria' => array(
					'scopes' => array(
						'citySearch','listing'
					),
				),
			),
			/***************土特产***************/
			'nativeList' => array(//土特产列表
				'class' => 'application.components.actions.front.ListAction',
			    'view' => 'native/list',
				'modelName' => 'Native',
				'criteria' => array(
					'scopes' => array(
						'listing'
					),
				),
				'pageSize' => 12,
			),
			'nativeView' => array(//土特产详情页
				'class' => 'application.components.actions.front.ViewAction',
			    'view' => 'native/view',
				'modelName' => 'Native'
			),
			'nativeWrite' => array(//土特产订单填写
				'class' => 'application.components.actions.front.OrderAction',
				'view' => 'native/orderWrite',
				'returnUrl' => array('success')
			),
		);
	}
	
	//定单填写成功
    public function actionSuccess($id){
        $this->render('scenic/success',array('model'=>Order::model()->findByPk($id)));
    }

    //酒店频道首页
    public function actionHotelIndex(){
        $this->render('hotelIndex');
    }
    
    //酒店详情
    public function actionHotelView($id){
         $data = CompanyHotel::model()->findByPk($id);
         $this->render('hotel/view',array(
             'model'=>$data,
         ));
    }
    
    //旅游频道首页
    public function actionTourIndex(){
        $this->render('tourIndex');
    }
    
    //旅游详情
    public function actionTravelView(){
         $model = new Travel();
         $data = $model->findByPk($_GET['id']);
         $this->render('travel/view',array(
             'model'=>$data,
         ));
    }
    
    //土特产频道首页
    public function actionNativeIndex(){
        $this->render('nativeIndex');
    }
    
    public function actionComment($type,$id) {
    	$modelName = null;

    	switch ($type) {
			case 'Hotel':
				$modelName = 'CompanyHotel';
				break;
			case 'Scenic':
				$modelName = 'CompanyScenic';
				break;
			default:
				$modelName = $type;
			break;
		}
		$goods = new $modelName;
    	$goods = $goods->findByPk($id);
		
		$this->render('comment',array(
			'type' => $type,
			'model' => $goods
		));
    }
    
    public function actionCommentPartial($type, $id, $rate = null) {
    	if (!Yii::app()->request->isAjaxRequest) return false;
    	$model = new GoodsComment('search');
		$model->target_object_id = $id;
		$model->target_object_type = $type;
		$model->rate = $rate;
		
		if (isset($_GET['GoodsComment'])) {
			$model->attributes = $_GET['GoodsComment'];
		}
		
    	$this->renderPartial('comment/list',array(
    		'data' => $model->commentSearch(),
			'model' => $model,
    	));
    }
}

?>